package com.dingding.service.activity.core.dao.impl;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.beans.PreferentialActivity;
import com.dingding.service.activity.core.dao.IPreferentialActivityDao;
import com.dingding.service.activity.core.sql.PreferentialActivitySQL;

/**
 * 
 * @ClassName: IPreferentialActivityDao 
 * @Description: 优惠活动表DAO
 * @author CHEHAUNBO 
 * @date 2016年4月1日 上午9:32:11
 * 
 */
@Component("preferentialActivityDao")
public class PreferentialActivityDaoImpl extends BaseDaoImpl<PreferentialActivity> implements IPreferentialActivityDao {

	/**
	 * @Title: resetPreferentialActivity
	 * @Description: 重置优惠券活动
	 * @author yuHaiQing
	 * @return boolean    true:重置成功  false:重置失败
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean resetPreferentialActivity() {
		// 将过期的优惠券活动改为无效,并返回受影响的行数
		int row = -1;
		try {
			row = super.updateSqlRow(PreferentialActivitySQL.RESET_INVALID_PREFERENTIAL_ACTIVITY);
		} catch (Exception e) {
			log.error("重置优惠券活动时出现异常   类：" + this.getClass() + " resetPreferentialActivity()", e);
		}

		// 判断是否重置成功，如果小于0，修改失败
		if (row < 0) {
			return false;
		}
		return true;
	}

}
